<?php
/**
 * @author 天涯 <mail@phpha.com>
 * @copyright http://blog.phpha.com
 * @link http://blog.phpha.com/vncms
 * @version 1.0
 */
defined('APP_PATH') or exit('Access Denied');
class open extends spController{
	//登录系统
	public function login(){
		if(!empty($_SESSION['admin'])){
			$this->jump(spUrl('admin','index'));
		}
		if($this->spArgs('vonuo') && $this->spArgs('com') && $this->spArgs('imgvc')){
			if(empty($_SESSION['verify']) || $_SESSION['verify'] !== md5(trim($this->spArgs('imgvc')))){
				$this->error('验证码错误！',spUrl('open','login'));
			}elseif(false == spClass('m_admin')->check($this->spArgs('vonuo'), $this->spArgs('com'))){
				$this->error('用户名或密码错误！',spUrl('open','login'));
			}elseif($_SESSION['admin']['status'] == 0){
				unset($_SESSION['admin']);
				$this->error('您的账号已被禁用！',spUrl('open','login'));
			}else{
				spClass('m_logs')->add();
				$this->jump(spUrl('admin','index'));
			}
		}
		$this->display('login.tpl.php');
	}
	//退出系统
	public function logout(){
		if(!empty($_SESSION['admin'])){
			unset($_SESSION['admin']);		
		}
		$this->jump(spUrl('open','login'));
	}
	//验证码
	public function imgvc(){
		require 'comm/Include/Image.class.php';
		Image::buildImageVerify();
	}
	public function success($msg, $url = ''){
		$this->msg = $msg;
		$this->url = $url;
		$this->display('message.tpl.php');
		exit;
	}
	public function error($msg, $url = ''){
		$this->msg = $msg;
		$this->url = $url;
		$this->display('message.tpl.php');
		exit;
	}
	//Ajax检测表名
	public function checktable(){
		if($tablename = trim($this->spArgs('tablename'))){
			echo spClass('m_table')->check_table($tablename);
		}else{
			exit('Access Denied');
		}
	}
	//Ajax检测字段
	public function checkfield(){
		if(($field = trim($this->spArgs('field'))) && ($tablename = trim($this->spArgs('tablename')))){
			echo spClass('m_field')->check_field($field,$tablename);
		}else{
			exit('Access Denied');
		}
	}
}
